package jp.syuriken.snsw.terenaibot.format.function;

import java.util.Random;

import jp.syuriken.snsw.terenaibot.format.CompileArg;
import jp.syuriken.snsw.terenaibot.format.FormatSyntaxException;
import jp.syuriken.snsw.terenaibot.format.PrecompiledSyntaxGroup;

/**
 * TODO snsoftware
 * 
 * @author $Author: snswinhaiku.lo@gmail.com $ */
public class RandFunction extends AbstractFormatFunction {
	
	private Random random;
	

	public RandFunction() {
		random = new Random();
	}
	
	@Override
	public String getReturnValue(PrecompiledSyntaxGroup[] args, CompileArg compileArg) throws FormatSyntaxException {
		checkArgLength(args, compileArg, "rand", 1, -1);
		return args[random.nextInt(args.length)].format(compileArg);
	}
	
}
